<div class="pageContent">
	<form method="post" action="#" class="pageForm required-validate">
		<div class="pageFormContent">
			<input type="hidden" name="workUnitCode" value="${workUnitCode}">
			<input type="hidden" name="group" value="${andonGroup}">
			<fieldset class="dataset">
				<dl>
					<dt><@label key="andonCode.C,colon">ANDON编号：</@label></dt>
					<dd>
						<input name="andonCode" autocomplete="off" value="${andon.andonCode}" size="32" type="text" maxlength="20" class="required alphanumeric toUp"
						<#if pattern!="add">
							readonly="readonly"
						<#else>
							remote="${rc.getContextPath()}/manage/andon/validateAndonCode?workUnitCode=${workUnitCode}"
							warn="<@label key='underWorkUnit.C,andonCode.C,alreadyExists'>ANDON编号已存在</@label>"
						</#if>
						/>
					</dd>
				</dl>
				<dl>
					<dt><@label key="andonText.C,colon">ANDON描述：</@label></dt>
					<dd>
						<input name="andonText" autocomplete="off" value="${andon.andonText}" size="32" type="text" maxlength="60" class="required"
						<#if pattern=="view">
							readonly="readonly"
						</#if>
						/>
					</dd>
				</dl>
				<dl>
					<dt><@label key="andonTemplate.C,colon">ANDON模板：</@label></dt>
					<dd>
						<select id="template" name="templateCode" class="required"
						<#if pattern=="view">
							disabled="disabled"
						</#if>
						> 
							<#list templates as template>
								<option value="${template.templateCode}"
								<#if template.templateCode == andon.templateCode>
									selected="selected"
								</#if>
								>${template.templateText}</option>
							</#list>
						</select>
					</dd>
				</dl>
				<dl>
					<dt><@label key="andonType.C,colon">ANDON类型：</@label></dt>
					<dd>
						<input id="andonType" readonly="readonly" size="32" type="text" maxlength="60" />
					</dd>
				</dl>
				<dl>
					<dt><@label key="event.C,colon">事件：</@label></dt>
					<dd>
						<input id="event" readonly="readonly" size="32" type="text" maxlength="60" />
					</dd>
				</dl>
				<dl>
					<dt><@label key="andonMessageRule.C,colon">消息通知规则：</@label></dt>
					<dd>
						<input id="messageRule" readonly="readonly" size="32" type="text" maxlength="60" />
					</dd>
				</dl>
				<dl class="nowrap">
					<dd style="width: 100%; height: 200px;">
						<div id="jGridForTemplateAttributes"></div>
					</dd>
				</dl>
				<dl>
					<dt>&nbsp;</dt>
					<dd>
						<label style="width: 80px;"> 
							<input id="alarmFlag" disabled="disabled" type="checkbox" value="1" /><@label key="alarm.C">报警</@label>
						</label>
					</dd>
				</dl>
				<dl>
					<dt>&nbsp;</dt>
					<dd>
						 <label style="width: 80px;"> 
						 	<input name="lockFlag" type="checkbox" value="1"
						 	<#if pattern=="view">
								disabled="disabled"
							</#if>
							<#if andon.lockFlag?? && andon.lockFlag == 1>
								checked="checked"
							</#if>
						 	/><@label key="lock.C">锁定</@label>
						</label>
					</dd>
				</dl>
			</fieldset>
			<#if andon??>
				<#assign createInfo=andon>
				<#include "/common/createInfo.html">
			</#if>
			<div class="formBar">
				<ul>
					<#if pattern!="view">
					<li>
						<div class="buttonActive">
							<div class="buttonContent">
								<button id="saveAndon" type="submit" name="btnSave"><@label key="save.B">保存</@label></button>
							</div>
						</div>
					</li>
					<li>
						<div class="buttonActiveGrey" style="margin-left: 10px;">
							<div class="buttonContent">
								<button type="button" class="close"><@label key="cancel.B">取消</@label></button>
							</div>
						</div>
					</li>
					<#else>
                    <li>
                    	<div class="buttonActive">
							<div class="buttonContent">
								<button type="button" class="close"><@label key="close.B">关闭</@label></button>
							</div>
						</div>
	                </li>
                	</#if>
				</ul>
			</div>
	</form>
</div>
<script>
$(function(){
	var $page = DWZ.context(), $andonType = $page.find('#andonType'), 
	$event = $page.find('#event'), $messageRule = $page.find('#messageRule'),
	$alarmFlag = $page.find('#alarmFlag'),
	$grid = $page.find('#jGridForTemplateAttributes').jGrid({
		autoLoad: false,
		inner: true,
		hasBorder: true,
		width: 590,
		height: 170,
		columns: [{
			field: '_index',
			text: '<@label key="serialNumber.C">序号</@label>',
			width: 40
		}, {
			field: 'attributeCode',
			text: '<@label key="name.C">名称</@label>',
			width: 100
		}, {
			field: 'attributeValue',
			text: '<@label key="Value.C">值</@label>',
			width: 100
		}]
	}),
	$template = $page.find('#template').change(function(){
		var templateCode = this.value;
		if (!templateCode) {
			return;
		}
		DWZ.ajax({
			url: hostUrl + '/andon/getAndonTemplateDetail',
			data: {
				templateCode: templateCode
			},
			success: function(t) {
				if (t) {
					$andonType.val(t.andonTypeText);
					$event.val(t.eventText);
					$messageRule.val(t.ruleText);
					$alarmFlag.attr('checked', t.alarmFlag == 1);
					$grid.jGrid('fillGrid', t.andonTemplateAttributeList || []);
				} else {
					$andonType.val('');
					$event.val('');
					$messageRule.val('');
					$alarmFlag.attr('checked', false);
					$grid.jGrid('clearData');
				}
			}
		});
	}).change();
	
	$page.find('#saveAndon').click(function(){
		var $this = $(this), $form = $this.closest('form');
		if (!$form.valid()) {
			return false;
		}
		var url = hostUrl + '/andon/saveAndon?isUpdate=${isUpdate}';
		DWZ.ajax({
			url: url,
			data: $form.serializeArray(),
			success: function() {
				$.pdialog.closeCurrent();
				$page.data('_parent').find('#jGridForAndonList').jGrid('loadData');
			}
		});
		return false;
	});
});
</script>
